import { Injectable } from '@nestjs/common';
import { KsDto } from './dto/ks.dto';
import { HttpService } from '@nestjs/axios';
import { DataBaseDto } from './dto/data-base.dto';
// import * as sdk from '@baiducloud/sdk';
import { TaskDto } from './dto/task.dto';
import { BaiduCloudClient } from 'utils/baiduCloudClient';
import { ImportDataDto } from './dto/importData.dto';


@Injectable()
export class LargeModelService {
  constructor(private httpService: HttpService) {}

  //NOTE(@date:2023-12-24 15:34:40 谭人杰): 获取TOKEN 用于机器人问答等
  async getToken(params: KsDto): Promise<any> {
    const response = await this.httpService
      .get(
        `https://aip.baidubce.com/oauth/2.0/token?grant_type=${params.grantType}&client_id=${params.clientId}&client_secret=${params.clientSecret}`,
      )
      .toPromise();
    return response.data;
  }

  //NOTE(@date:2023-12-24 16:16:18 谭人杰): 用来做测试的服务
  async testService(): Promise<any> {
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    const sdk = require('@baiducloud/sdk');
    const config = {
      credentials: {
        ak: 'ALTAK8RKsqz0GWmrUfJSKe34wd',
        sk: 'f75c04297e7a43c786b63c07bc661d1b',
      },
      endpoint: 'https://qianfan.baidubce.com',
    };

    const client = new sdk.HttpClient(config);
    const path = '/wenxinworkshop/dataset/create';

    const body = JSON.stringify({
      name: 'tttt',
      projectType: 401,
      templateType: 40100,
      dataType: 4,
      storageType: 'sysBos',
    });

    const params = {};
    const headers = { 'Content-Type': 'application/json' };
    client.sendRequest('POST', path, body, headers, params).then(
      function (response) {
        console.log('object: ', response.body);
      },
      function (error) {
        console.log('error: ', error);
      },
    );
  }

  //NOTE(@date:2023-12-24 15:35:05 谭人杰): 创建数据集
  async createDataBase(dataBaseDto: DataBaseDto): Promise<any> {
    console.log('dataBaseDto======', dataBaseDto);

    const temp: BaiduCloudClientTypes = {
      request: {
        config: {
          path: dataBaseDto.path,
        },
        args: {
          body: JSON.stringify({
            name: dataBaseDto.name,
            projectType: Number(dataBaseDto.projectType),
            templateType: Number(dataBaseDto.templateType),
            dataType: Number(dataBaseDto.dataType),
            storageType: dataBaseDto.storageType,
          }),
          params: {},
        },
      },
    };
    console.log('config====', temp);
    const client = new BaiduCloudClient(temp);
    client.init();
    const res = await client.sendRequest();
    return res;
  }
}
